package com.yuqih.common.servlet;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;

public class RequestContextFilterConfig {

	private ExecutorService executor;

	private String[] remoteIpHeaderNames;
	private List<String> excludeUris;
	private IRequestContextLogger logger;

	@PostConstruct
	public void init() {
		if (excludeUris != null) {
			List<String> excludes = new ArrayList<String>();

			for (String exclude : excludeUris) {
				if (StringUtils.isNotBlank(exclude)) {
					excludes.add(StringUtils.trim(exclude));
				}
			}
			this.excludeUris = excludes;
		}

		List<String> headers = new ArrayList<String>();
		if (remoteIpHeaderNames != null) {
			String header = null;
			for (int i = 0; i < remoteIpHeaderNames.length; i++) {
				header = StringUtils.trim(remoteIpHeaderNames[i]);
				if (StringUtils.isNotBlank(header)) {
					headers.add(header);
				}

			}			
		}
		this.remoteIpHeaderNames = headers.toArray(new String[headers.size()]);

	}
	
	

	/**
	 * @return the executor
	 */
	public ExecutorService getExecutor() {
		return executor;
	}



	/**
	 * @return the remoteIpHeaderNames
	 */
	public String[] getRemoteIpHeaderNames() {
		return remoteIpHeaderNames;
	}

	/**
	 * @param remoteIpHeaderNames
	 *            the remoteIpHeaderNames to set
	 */
	public void setRemoteIpHeaderNames(String[] remoteIpHeaderNames) {
		this.remoteIpHeaderNames = remoteIpHeaderNames;
	}
	
	/**
	 * @return the excludeUris
	 */
	public List<String> getExcludeUris() {
		return excludeUris;
	}

	/**
	 * @param excludeUris
	 *            the excludeUris to set
	 */
	public void setExcludeUris(List<String> excludeUris) {
		this.excludeUris = excludeUris;
	}

	/**
	 * @return the logger
	 */
	public IRequestContextLogger getLogger() {
		return logger;
	}

	/**
	 * @param logger
	 *            the logger to set
	 */
	public void setLogger(IRequestContextLogger logger) {
		this.logger = logger;
	}

	/**
	 * @param executor the executor to set
	 */
	public void setExecutor(ExecutorService executor) {
		this.executor = executor;
	}

}
